(function (vc, vm) {
    vc.extends({
        data: {
            editIndexMenuInfo: {
                menuId: '',
                name: '',
                menuIcon: '',
                seq: '',
                isShow: '',
                isShows: []
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editIndexMenu', 'openEditIndexMenuModal', function (_params) {
                $that.refreshEditIndexMenuInfo();
                $('#editIndexMenuModel').modal('show');
                vc.getDict('housekeeping_type', "is_show", function (_data) {
                    $that.editIndexMenuInfo.isShows = _data;
                });
                vc.copyObject(_params, $that.editIndexMenuInfo);
                let _photos = [];
                _photos.push(_params.menuIcon);
                vc.emit('editIndexMenu', 'uploadImageUrl', 'notifyPhotos', _photos);
            });
            vc.on("editIndexMenu", "notifyUploadCoverImage", function (_param) {
                if (_param.length > 0) {
                    $that.editIndexMenuInfo.menuIcon = _param[0].url;
                } else {
                    $that.editIndexMenuInfo.menuIcon = '';
                }
            });
        },
        methods: {
            editIndexMenuValidate: function () {
                return vc.validate.validate({
                    editIndexMenuInfo: $that.editIndexMenuInfo
                }, {
                    'editIndexMenuInfo.name': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "菜单名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "菜单名称名称太长"
                        },
                    ],
                    'editIndexMenuInfo.menuIcon': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "小图标不能为空"
                        }
                    ],
                    'editIndexMenuInfo.seq': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "排序不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "排序不是有效数字"
                        },
                    ],
                    'editIndexMenuInfo.isShow': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "是否显示不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "2",
                            errInfo: "是否显示格式错误"
                        },
                    ],
                    'editIndexMenuInfo.menuId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "菜单编号不能为空"
                        }
                    ]
                });
            },
            editIndexMenu: function () {
                if (!$that.editIndexMenuValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.editIndexMenuInfo.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/shopMenu.updateShopMenu',
                    JSON.stringify($that.editIndexMenuInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        vc.toast(_json.msg);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editIndexMenuModel').modal('hide');
                            vc.emit('indexMenu', 'listMenu', {});
                            return;
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditIndexMenuInfo: function () {
                $that.editIndexMenuInfo = {
                    menuId: '',
                    name: '',
                    menuIcon: '',
                    seq: '',
                    isShow: '',
                    isShows: []
                }
            }
        }
    });
})(window.vc, window.$that);
